<template>
  <view :style="themeColor">
    <view class="page">
      <view class="flex flex-wrap align-center justify-between benben-position-layout flex phoneNumber_flex_0"
        :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
        <view class='flex flex-wrap align-center phoneNumber_fd0_0' @tap.stop="handleJumpDiy" data-type="back"
          data-url="1">
          <image class='phoneNumber_fd0_0_c0' mode="aspectFit" :src='STATIC_URL+"234.png"'></image>
        </view>
        <view class='flex flex-wrap align-center phoneNumber_fd0_0'>
        </view>

      </view>
      <view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
      <!---flex布局flex布局开始-->
      <view class="flex flex-direction flex-wrap align-stretch benben-flex-layout phoneNumber_flex_1">
        <view class='flex flex-wrap align-center justify-center phoneNumber_fd1_0'>
          <image class='phoneNumber_fd1_0_c0' mode="aspectFit" :src='STATIC_URL+"222.png"'></image>
        </view>
        <view class='flex flex-wrap align-center phoneNumber_fd1_1'>
          <image class='phoneNumber_fd1_1_c0' mode="aspectFit" :src='STATIC_URL+"230.png"'></image>
          <benben-input class='flex-sub phoneNumber_fd1_1_c1' type="number" :placeholder="$t('请输入手机号')"
            confirm-type="done" :maxlength="11" placeholder-style="color:#999;font-size:32rpx" v-model="mobile" />
        </view>
        <view class='flex flex-wrap align-center phoneNumber_fd1_2'>
          <image class='phoneNumber_fd1_1_c0' mode="aspectFit" :src='STATIC_URL+"232.png"'></image>
          <benben-input class='flex-sub phoneNumber_fd1_1_c1' type="number" :placeholder="$t('请输入验证码')"
            confirm-type="done" :maxlength="6" placeholder-style="color:#999;font-size:32rpx" v-model="code" />
          <benben-send-verification-code key='1707098709297' ref="vCode1707098709297" class=' phoneNumber_fd1_2_c2'
            :after-text="$t('后重新获取')" :before-text="$t('获取验证码')" :emptye-text="$t('请输入手机号')"
            :validate-text="$t('请输入正确的手机号')" account-type='phone' :auto='true' type='3'
            :phone="mobile"></benben-send-verification-code>
        </view>
        <view class='flex flex-wrap align-center phoneNumber_fd1_2'>
          <image class='phoneNumber_fd1_1_c0' mode="aspectFit" :src='STATIC_URL+"231.png"'></image>
          <benben-flex-password-diy v-model="password" class-name="flex flex align-center phoneNumber_fd1_3_c1"
            :placeholder="$t('请输入密码(6~12位字母+数字)')" :maxlength="12" :default-type='true'
            placeholder-style="color:#999;font-size:32rpx">
            <template #show>
              <text class='fu-iconfont2  phoneNumber_fd1_3_c1_icon1' data-type="show">&#xE837;</text>
            </template>
            <template #hide>
              <text class='fu-iconfont2  phoneNumber_fd1_3_c1_icon1' data-type="hide">&#xEBCC;</text>
            </template>
          </benben-flex-password-diy>
        </view>
        <!-- <view class='flex flex-wrap align-center phoneNumber_fd1_2'>
          <image class='phoneNumber_fd1_1_c0' mode="aspectFit" :src='STATIC_URL+"233.png"'></image>
          <benben-input class='flex-sub phoneNumber_fd1_1_c1' type="text" :placeholder="$t('请输入邀请码（选填）')"
            confirm-type="done" :maxlength="-1" placeholder-style="color:#999;font-size:32rpx" v-model="invite_code" />
        </view> -->
        <button class='phoneNumber_fd1_5' @tap.stop="bangdmobileFunc()">{{$t('确定')}}</button>
      </view>

      <!---flex布局flex布局结束-->


    </view>
  </view>
</template>
<script>
  import {
    validate
  } from '@/common/utils/validate.js'
  import md5 from 'js-md5';
  export default {
    components: {},


    data() {
      return {
        "is_tk": false,
        "code": "",
        "password": "",
        "dataUserInfo": {
          "userinfo": {
            "user_token": "",
            "id": "",
            "avatar": "",
            "real_name": "",
            "nickname": "",
            "email": "",
            "gender": "",
            "mobile": "",
            "birthday": "",
            "client_id": "",
            "phone": ""
          }
        },
        "invite_code": "",
        "mobile": "",
        "third_type": "",
        "extend_info": "",
        id: ''
      };
    },
    computed: {
      themeColor() {
        return this.$store.getters.themeColor
      },

    },
    watch: {},
    onLoad(options) {
      let {
        third_type,
        id,
        extend_info
      } = options
      if (third_type !== undefined) this.third_type = third_type
      if (extend_info !== undefined) this.extend_info = extend_info
      if (id !== undefined) this.id = id
    },
    onUnload() {

    },
    onReady() {

    },
    onShow() {

    },
    onHide() {

    },
    onResize() {

    },
    onPullDownRefresh() {

    },
    onReachBottom(e) {

    },
    onPageScroll(e) {

    },
    methods: {
      //绑定手机号
      async bangdmobileFunc() {
        if (!validate(this.mobile, 'require')) {
          this.$message.info(global.i18n.t('请输入手机号'));
          return false;
        }
        if (!validate(this.mobile, 'phone')) {
          this.$message.info(global.i18n.t('请输入正确的手机号'));
          return false;
        }
        if (!validate(this.code, 'require')) {
          this.$message.info(global.i18n.t('请输入验证码'));
          return false;
        }
        if (!validate(this.code, 'captcha')) {
          this.$message.info(global.i18n.t('请输入正确的验证码'));
          return false;
        }
        if (!validate(this.password, 'require')) {
          this.$message.info(global.i18n.t('请输入密码'));
          return false;
        }
        if (!validate(this.password, 'password')) {
          this.$message.info(global.i18n.t('请输入正确的密码（6~12位字母+数字）'));
          return false;
        }
        //请求方法
        //数据验证

        // let Authorization = `Bearer ` + this.token
        // console.log('token', Authorization)
        // let uinfo = JSON.stringify(JSON.parse(uni.getStorageSync(
        //   'Wxinfo_tmp'))) //{"openid":"","unionid":"","gender":"","nickname":"","avatar":"","code":""}
        let datadataUserInfo = await this.$api.post(global.apiUrls.bindtelPhone, {
          telPhone: this.mobile,
          vCode: this.code,
          id: this.id,
          // account: this.mobile,
          // code: this.code,
          // code_type: '5',
          password: md5(this.password)
          // invite_code: this.invite_code,
          // account_type: 'mobile',
          // third_type: this.third_type,
          // extend_info: uinfo
        });

        if (datadataUserInfo.data.code != 0) {
          this.$message.info(datadataUserInfo.data.msg);
          return
        }
        let infodataUserInfo = datadataUserInfo.data;
        this.dataUserInfo = infodataUserInfo.data
        console.log('jiekou fanhu', this.dataUserInfo)
        this.$store.commit('saveToken', this.dataUserInfo.token)
        this.$store.commit('updateUserInfo', this.dataUserInfo)
        this.$urouter.switchTab(`/pages/tabBar/home/home`);
      },
      //绑定手机号废弃勿删
      async bangdingFunc() {
        //请求方法
        //数据验证

        let datadataUserInfo = await this.$api.dbPost(global.apiUrls.post5d7757d28d076, {
          account: this.mobile,
          code: this.code,
          code_type: '5',
          password: this.password,
          invite_code: this.invite_code,
          account_type: 'mobile',
          third_type: this.third_type,
          extend_info: this.extend_info
        });
        if (!datadataUserInfo) return
        if (datadataUserInfo.data.code != 1) {
          this.$message.info(datadataUserInfo.data.msg);
          return
        }
        let infodataUserInfo = datadataUserInfo.data;
        this.dataUserInfo = infodataUserInfo.data

      }
    }
  };
</script>
<style lang="scss" scoped>
  .page {
    width: 100vw;
    overflow-x: hidden;
    min-height: calc(100vh - var(--window-bottom));
    background: var(--benbenbgColor1);
    background-size: 100% auto;
  }

  .phoneNumber_flex_0 {
    width: 750rpx;
    height: 88rpx;
    overflow: hidden;
    z-index: 10;
    top: 0rpx;
  }

  .phoneNumber_fd0_0_c0 {
    width: 20rpx;
    height: 36rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    margin: 0rpx 0rpx 0rpx 32rpx;
  }

  .phoneNumber_fd0_0 {
    width: 100rpx;
    height: 88rpx;
  }

  .phoneNumber_flex_1 {
    padding: 0rpx 56rpx 0rpx 56rpx;
  }

  .phoneNumber_fd1_5 {
    background: var(--benbenbgColor7);
    border-radius: 50rpx 50rpx 50rpx 50rpx;
    font-size: 32rpx;
    color: var(--benbenFontColor3);
    width: 638rpx;
    height: 88rpx;
    line-height: 88rpx;
    margin: 104rpx 0rpx 32rpx 0rpx;
  }

  .phoneNumber_fd1_3_c1_icon1 {
    width: 88rpx;
    line-height: 88rpx;
    text-align: center;
    font-size: 40rpx;
  }

  ::v-deep .phoneNumber_fd1_3_c1 {
    height: 45rpx;
    width: 560rpx;
    font-size: 32rpx;
    margin: 0rpx 0rpx 0rpx 32rpx;
  }

  .phoneNumber_fd1_2_c2 {
    min-width: 250rpx;
    line-height: 42rpx;
    text-align: center;
    font-size: 28rpx;
    color: rgba(0, 167, 255, 1);
    border-radius: 21rpx 21rpx 21rpx 21rpx;
  }

  .phoneNumber_fd1_2 {
    border-bottom: 1px solid #eee;
    padding: 40rpx 0rpx 40rpx 0rpx;
  }

  .phoneNumber_fd1_1_c1 {
    height: 45rpx;
    margin: 0rpx 0rpx 0rpx 32rpx;
    color: var(--benbenFontColor0);
    font-size: 32rpx;
    font-weight: 400;
    line-height: 45rpx;
  }

  .phoneNumber_fd1_1_c0 {
    width: 34rpx;
    height: 34rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .phoneNumber_fd1_1 {
    border-bottom: 1px solid #eee;
    padding: 40rpx 0rpx 40rpx 0rpx;
    margin: 140rpx 0rpx 0rpx 0rpx;
  }

  .phoneNumber_fd1_0_c0 {
    width: 180rpx;
    height: 180rpx;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
  }

  .phoneNumber_fd1_0 {
    margin: 40rpx 0rpx 0rpx 0rpx;
  }
</style>
